﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace MetaHeuristics.Aco
{
    using MetaHeuristics.Aco.Collections;

    public class Ant : ICloneable
    {
        #region Fields
        private TourCollection tours;
        #endregion

        public Ant()
        {
            this.tours = new TourCollection();
        }

        public Ant(Ant ant)
        {
            if (ant == null)
                throw new ArgumentNullException("ant");
            this.tours = new TourCollection(ant.Tours);
        }

        public TourCollection Tours
        {
            get
            {
                return this.tours;
            }
        }

        public void CloseTour()
        {
            this.tours.Close();
        }

        public void AddCity(int cityIndex)
        {
            this.tours.Add(cityIndex);
        }

        public bool Visited(int cityIndex)
        {
            return this.tours.Contains(cityIndex);
        }

        public void Clear()
        {
            this.tours.Clear();
            this.tours.Length = 0;
        }

        public int LastCity
        {
            get
            {
                return this.tours[this.tours.Count - 1];
            }
        }

        public Ant Clone()
        {
            return new Ant(this);
        }

        Object ICloneable.Clone()
        {
            return this.Clone();
        }


        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("Ant({1}): ",this.tours.Count, this.Tours.Length);
            foreach(int i in this.tours)
                sb.AppendFormat(" {0}",i);
            return sb.ToString();
        }
    }
}
